package password;

import org.apaches.commons.codec.digest.DigestUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author jie
 * @version 创建时间：2018年9月13日 下午7:02:19
 * 类说明
 */
public class MD5Utils_Test {
    public static void main(String[] args) {
        String string = null;
        for (int i = 0; i < 1; i++) {
            String pwd = MD5Utils.md5Str("sk,f;lsa;fka;lfms;ldfkslafm;almf;lsamj;ljk;lm;mfds");
            System.out.println("MD5Utils.encrypt:"+pwd);
        }


        System.out.println(DigestUtils.md5Hex("1234"));

        String md5Src = "/Users/macpro/ideaWorkSpace/MyJava/src/password/bee/FC241118370001.dat";
//        String md5SrcFolder = "/Users/macpro/ideaWorkSpace/MyJava/src/password/bee";
        String md5SrcFolder = "/Users/macpro/ideaWorkSpace/MyJava/src/password/bee/nullFolder";
        String folderMD5Sum = MD5Utils.getFolderMD5Sum(new File(md5SrcFolder));
        System.out.println("MD5:main:Folder:" + folderMD5Sum);

        String s = MD5Utils.md5File(md5Src);
        System.out.println("MD5:main:md5Hex:" + s);

        String fileMD5 = MD5Utils.md5File2(md5Src);
        System.out.println("MD5:main:" + fileMD5 + " " + (fileMD5.equals(s)));


        String md5Jpeg = MD5Utils.md5File("./src/password/md5-liudehua.jpeg");

        for (int i = 2; i < 381; i++) {
            String md5 = MD5Utils.md5File("/Users/macpro/Pictures/beeboxes/Face_little/"+i+"a.jpg");
//            String md5 = md5File("/Users/macpro/Pictures/beeboxes/Face_little/"+i+"a.jpg");
            length(md5);
        }
    }

    //测试：正确的结果：
    //Length in characters: 32 Length in bits: 128
    public static void length(String md5Hash) {
        // 给定的MD5哈希值（十六进制字符串）
//        String md5Hash = "932603e39fdb9db21748846e2cdc39c3";

        // 计算字符串长度
        int lengthInChars = md5Hash.length();

        // 转换为位数（每个十六进制字符等于4位）
        int lengthInBits = lengthInChars * 4;

        // 输出结果
        System.out.println("MD5 Hash:" + md5Hash);
        System.out.println("Length in characters: " + lengthInChars+" Length in bits: " + lengthInBits);
    }

}
